using ASP;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml;
public class HL_Admin_Admin_LabelTemplateStatic : Admin, IRequiresSessionState
{
	protected ScriptManager ScriptManager1;
	protected HtmlGenericControl bar;
	protected Literal ParmList;
	protected TextBox LabelName;
	protected Button ShowButton2;
	protected Button ShowButton3;
	protected Literal ShowPlace;
	protected UpdatePanel UpdatePanel1;
	protected Button closeB;
	protected Panel Panel1;
	protected TextBox TemplateContent;
	protected Literal LabelParms;
	protected Literal SysLabel;
	protected DropDownList LabelClassSelect;
	protected Literal LabelList;
	protected Button PreStepButton;
	protected Button FinishButton;
	protected Button CreateLabelButton;
	protected Panel Panel2;
	private LabelBll _lb = null;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected LabelBll lb
	{
		get
		{
			LabelBll lb;
			if (this._lb == null)
			{
				this._lb = new LabelBll(this.conn);
				lb = this._lb;
			}
			else
			{
				lb = this._lb;
			}
			return lb;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.BindLabelList();
			this.BindPage();
			DataTable labelType = this.lb.GetLabelType();
			this.LabelClassSelect.DataSource = labelType;
			this.LabelClassSelect.DataTextField = "Type";
			this.LabelClassSelect.DataValueField = "Type";
			this.LabelClassSelect.DataBind();
			this.LabelName.Text = "{HL.Label ID=\"" + base.Request["name"] + "\" }";
			this.listParameter();
		}
	}
	public void listParameter()
	{
		string text;
		if (base.Request["action"] != null && base.Request["action"] == "add" && base.Request["name"] != null)
		{
			DataTable dataTable = (DataTable)this.Session[base.Request["name"]];
			text = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>";
			for (int i = 0; i < dataTable.Rows.Count; i++)
			{
				for (int j = 0; j < dataTable.Columns.Count; j++)
				{
					text = string.Concat(new string[]
					{
						text,
						"<",
						dataTable.Columns[j].ColumnName.ToString(),
						">",
						dataTable.Rows[i][j].ToString(),
						"</",
						dataTable.Columns[j].ColumnName.ToString(),
						">\n"
					});
				}
			}
			text += "</root>";
			text = text.Replace("<ParmArray>", "");
			text = text.Replace("</ParmArray>", "");
		}
		else
		{
			DataTable labelByLabelName = this.lb.GetLabelByLabelName(base.Request["name"]);
			if (labelByLabelName.Rows.Count <= 0)
			{
				base.Response.Write("找不到标签！可能已被删除！");
				base.Response.End();
			}
			text = labelByLabelName.Rows[0]["Define"].ToString();
			if (text == null || text == "")
			{
				base.Response.Write("错误的标签！");
				base.Response.End();
			}
		}
		XmlDocument xmlDocument = new XmlDocument();
		xmlDocument.LoadXml(text);
		XmlNodeList xmlNodeList = xmlDocument.SelectNodes("root/parms");
		if (xmlNodeList != null)
		{
			this.ParmList.Text = "";
			foreach (XmlNode xmlNode in xmlNodeList)
			{
				XmlNode xmlNode2 = xmlNode.SelectSingleNode("name");
				XmlNode xmlNode3 = xmlNode.SelectSingleNode("intro");
				if (xmlNode2 == null || xmlNode3 == null)
				{
					base.Response.Write("错误的标签参数！");
					base.Response.End();
				}
				Literal expr_30C = this.ParmList;
				expr_30C.Text += "<div style=\"width:100%; text-align:left;\">\n";
				Literal expr_328 = this.ParmList;
				expr_328.Text = expr_328.Text + "    <div style=\"float:left; width:15%; text-align:right; line-height:25px;\">" + xmlNode3.InnerXml + "：</div>\n";
				Literal expr_350 = this.ParmList;
				string text2 = expr_350.Text;
				expr_350.Text = string.Concat(new string[]
				{
					text2,
					"    <div style=\"float:left;\"><input onblur=\"return SetParam(this)\" id=\"",
					xmlNode2.InnerXml,
					"\" name=\"",
					xmlNode2.InnerXml,
					"\"/></div>\n"
				});
				Literal expr_3C2 = this.ParmList;
				expr_3C2.Text += "</div>\n";
			}
		}
	}
	protected void BindPage()
	{
		DataTable labelByType = this.lb.GetLabelByType("");
		if (labelByType.Rows.Count > 0)
		{
			foreach (DataRow dataRow in labelByType.Rows)
			{
				Literal expr_50 = this.LabelList;
				string text = expr_50.Text;
				expr_50.Text = string.Concat(new string[]
				{
					text,
					"<div title=\"",
					dataRow["Name"].ToString(),
					"\" onclick=\"cit()\" onmousedown=\"dit(1)\" class=\"label_square\" value=\"",
					dataRow["Name"].ToString(),
					"\">"
				});
				if (dataRow["Name"].ToString().Length > 8)
				{
					Literal expr_F7 = this.LabelList;
					expr_F7.Text += dataRow["Name"].ToString().Substring(0, 8);
				}
				else
				{
					Literal expr_12C = this.LabelList;
					expr_12C.Text += dataRow["Name"].ToString();
				}
				Literal expr_154 = this.LabelList;
				expr_154.Text = expr_154.Text + "</div>" + Environment.NewLine;
			}
		}
		Literal expr_1A7 = this.SysLabel;
		expr_1A7.Text = expr_1A7.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"SiteName\">网站名称</div>" + Environment.NewLine;
		Literal expr_1C8 = this.SysLabel;
		expr_1C8.Text = expr_1C8.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"Logo\">网点Logo</div>" + Environment.NewLine;
		Literal expr_1E9 = this.SysLabel;
		expr_1E9.Text = expr_1E9.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"InstallDir\">站点安装路径</div>" + Environment.NewLine;
		Literal expr_20A = this.SysLabel;
		expr_20A.Text = expr_20A.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"Banner\">网点Banner</div>" + Environment.NewLine;
		Literal expr_22B = this.SysLabel;
		expr_22B.Text = expr_22B.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"WebMaster\">站长名</div>" + Environment.NewLine;
		Literal expr_24C = this.SysLabel;
		expr_24C.Text = expr_24C.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"WebMasterEmail\">站长名Email</div>" + Environment.NewLine;
		Literal expr_26D = this.SysLabel;
		expr_26D.Text = expr_26D.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"SiteUrl\">网站Url</div>" + Environment.NewLine;
		Literal expr_28E = this.SysLabel;
		expr_28E.Text = expr_28E.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"PageTitle\">当前页面标题</div>" + Environment.NewLine;
		Literal expr_2AF = this.SysLabel;
		expr_2AF.Text = expr_2AF.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"UserCookies\">曾经登录用户名</div>" + Environment.NewLine;
		Literal expr_2D0 = this.SysLabel;
		expr_2D0.Text = expr_2D0.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"LogingUserName\">当前登录用户名</div>" + Environment.NewLine;
		Literal expr_2F1 = this.SysLabel;
		expr_2F1.Text = expr_2F1.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"LogingUserID\">当前登录用户ID</div>" + Environment.NewLine;
		Literal expr_312 = this.SysLabel;
		expr_312.Text = expr_312.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"CopyRight\">版权信息</div>" + Environment.NewLine;
		if (base.Request["action"] != null && base.Request["name"] != null)
		{
			DataTable dataTable = new DataTable();
			if (base.Request["action"] == "add")
			{
				if (this.Session["Parm_Table_" + base.Request["name"]] != null)
				{
					dataTable = (DataTable)this.Session["Parm_Table_" + base.Request["name"]];
				}
				this.CreateLabelButton.Text = "请先保存";
				this.CreateLabelButton.Enabled = false;
			}
			else
			{
				if (base.Request["action"] == "modify" && base.Request["id"] != null && base.Request["id"] != "0")
				{
					int labelID = int.Parse(base.Request["id"]);
					DataTable labelByLabelID = this.lb.GetLabelByLabelID(labelID);
					if (labelByLabelID.Rows.Count == 1)
					{
						dataTable = this.lb.GetParmDataTable(labelByLabelID.Rows[0]["Define"].ToString());
						if (!base.IsPostBack)
						{
							this.TemplateContent.Text = labelByLabelID.Rows[0]["Template"].ToString();
						}
					}
					this.CreateLabelButton.Text = "更新静态";
				}
			}
			if (dataTable != null && dataTable.Rows.Count > 0)
			{
				foreach (DataRow dataRow in dataTable.Rows)
				{
					Literal expr_56F = this.LabelParms;
					string text = expr_56F.Text;
					expr_56F.Text = string.Concat(new string[]
					{
						text,
						"<div onclick=\"cit()\" onmousedown=\"dit(2)\" class=\"label_square\" value=\"",
						dataRow["name"].ToString(),
						"\">",
						dataRow["intro"].ToString(),
						"</div>",
						Environment.NewLine
					});
				}
			}
			else
			{
				if (base.Request["action"] != null && base.Request["action"] == "modify")
				{
					this.LabelParms.Text = string.Concat(new string[]
					{
						"你还没有添加作何参数<a href=\"Admin_LabelParms.aspx?action=modify&name=",
						base.Request["name"],
						"&id=",
						base.Request["id"],
						"\" class=\"label_square\">添加标签</a>"
					});
				}
				else
				{
					this.LabelParms.Text = "你还没有添加作何参数<a href=\"Admin_LabelParms.aspx?action=add&name=" + base.Request["name"] + "\" class=\"label_square\">添加标签</a>";
				}
			}
		}
	}
	protected void BindLabelParm()
	{
	}
	protected void ShowButton_Click(object sender, EventArgs e)
	{
		if (this.LabelName.Text != null && this.TemplateContent.Text != null)
		{
			string text = Template.TransferLabelToHtml(this.TemplateContent.Text, false);
			this.ShowPlace.Text = text;
			this.ShowButton2.Text = "刷 新";
			this.ShowButton3.Text = "源 码";
		}
	}
	protected void ShowButton_Click2(object sender, EventArgs e)
	{
		if (this.ShowPlace.Text != "" && this.ShowPlace.Text != null)
		{
			if (this.ShowButton3.Text == "源 码")
			{
				this.ShowPlace.Text = base.Server.HtmlEncode(this.ShowPlace.Text);
				this.ShowButton3.Text = "效 果";
			}
			else
			{
				if (this.ShowButton3.Text == "效 果")
				{
					this.ShowPlace.Text = base.Server.HtmlDecode(this.ShowPlace.Text);
					this.ShowButton3.Text = "源 码";
				}
			}
		}
	}
	protected void select_LabelClassSelect(object sender, EventArgs e)
	{
		this.LabelList.Text = "";
		DataTable labelByType;
		if (this.LabelClassSelect.SelectedValue == "全部标签")
		{
			labelByType = this.lb.GetLabelByType("");
		}
		else
		{
			labelByType = this.lb.GetLabelByType(this.LabelClassSelect.SelectedValue);
		}
		if (labelByType.Rows.Count > 0)
		{
			foreach (DataRow dataRow in labelByType.Rows)
			{
				Literal expr_A0 = this.LabelList;
				string text = expr_A0.Text;
				expr_A0.Text = string.Concat(new string[]
				{
					text,
					"<div title=\"",
					dataRow["Name"].ToString(),
					"\" onclick=\"cit()\" onmousedown=\"dit(1)\" class=\"label_square\" value=\"",
					dataRow["Name"].ToString(),
					"\">"
				});
				if (dataRow["Name"].ToString().Length > 8)
				{
					Literal expr_147 = this.LabelList;
					expr_147.Text += dataRow["Name"].ToString().Substring(0, 8);
				}
				else
				{
					Literal expr_17C = this.LabelList;
					expr_17C.Text += dataRow["Name"].ToString();
				}
				Literal expr_1A4 = this.LabelList;
				expr_1A4.Text = expr_1A4.Text + "</div>" + Environment.NewLine;
			}
		}
	}
	protected void BindLabelList()
	{
		this.TemplateContent.Attributes.Add("onmouseup", "dragend();");
		this.TemplateContent.Attributes.Add("onmousemove", "movePoint();");
	}
	protected void BindJsToControl()
	{
	}
	protected void PreStepButton_Click(object sender, EventArgs e)
	{
		if (base.Request["action"] != null)
		{
			if (base.Request["action"] == "add")
			{
				base.Response.Redirect("Admin_LabelParms.aspx?action=add&id=0&name=" + base.Request["name"]);
			}
			else
			{
				base.Response.Redirect("Admin_LabelParms.aspx?action=modify&id=" + base.Request["id"] + "&name=" + base.Request["name"]);
			}
		}
	}
	protected void FinishButton_Click(object sender, EventArgs e)
	{
		if (base.Request["name"] != null && base.Request["name"] != "" && base.Request["action"] != null)
		{
			if (base.Request["action"] == "add" && this.Session[base.Request["name"]] != null)
			{
				DataTable dataTable = (DataTable)this.Session[base.Request["name"]];
				if (dataTable.Rows.Count > 0)
				{
					DataRow dataRow = dataTable.Rows[0];
					string name = dataRow["Name"].ToString();
					string type = dataRow["Type"].ToString();
					string intro = dataRow["LabelIntro"].ToString();
					string dataType = dataRow["LabelDataType"].ToString();
					string cacheTime = dataRow["CacheTime"].ToString();
					string outPutType = dataRow["LabelType"].ToString();
					string text = this.TemplateContent.Text;
					string parmArray = dataRow["ParmArray"].ToString();
					string labelOutPutType = dataRow["OutPutType"].ToString();
					string labelStaticOutPut = dataRow["StaticOutPut"].ToString();
					if (this.lb.AddLabel(name, type, intro, dataType, cacheTime, outPutType, "", text, "", "", labelOutPutType, labelStaticOutPut, parmArray))
					{
						this.Session.Remove(base.Request["name"]);
						this.Session.Remove("Parm_Table_" + base.Request["name"]);
						base.Response.Redirect("Admin_Lable.aspx");
					}
				}
			}
			else
			{
				if (base.Request["action"] == "modify" && base.Request["id"] != "0")
				{
					int iD = int.Parse(base.Request["id"]);
					string[,] parmArray2 = new string[0, 0];
					if (this.lb.UpdateLabel(iD, "", "", "", "", "", "", "", this.TemplateContent.Text, "", "", "", "", "", parmArray2))
					{
						base.Response.Redirect("Admin_Lable.aspx");
					}
					else
					{
						this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert('保存数据出错！请联系管理员')</script>", false);
					}
				}
			}
		}
	}
	protected string GetLabelHTML()
	{
		string text;
		if (base.Request["action"] != null && base.Request["action"] == "add" && base.Request["name"] != null)
		{
			DataTable dataTable = (DataTable)this.Session[base.Request["name"]];
			text = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<root>";
			for (int i = 0; i < dataTable.Rows.Count; i++)
			{
				for (int j = 0; j < dataTable.Columns.Count; j++)
				{
					text = string.Concat(new string[]
					{
						text,
						"<",
						dataTable.Columns[j].ColumnName.ToString(),
						">",
						dataTable.Rows[i][j].ToString(),
						"</",
						dataTable.Columns[j].ColumnName.ToString(),
						">\n"
					});
				}
			}
			text += "</root>";
			text = text.Replace("<ParmArray>", "");
			text = text.Replace("</ParmArray>", "");
		}
		else
		{
			text = "";
		}
		return Template.GetContentFormLabel(this.LabelName.Text, text, this.TemplateContent.Text, false);
	}
	protected void CreateLabel_Click(object sender, EventArgs e)
	{
		string a = "";
		if (!string.IsNullOrEmpty(this.LabelName.Text) && !string.IsNullOrEmpty(this.TemplateContent.Text))
		{
			string text = base.Request["action"];
			if (text != null)
			{
				if (!(text == "add"))
				{
					if (text == "modify")
					{
						if (base.Request["id"] != null && base.Request["id"] != "0")
						{
							try
							{
								int labelID = int.Parse(base.Request["id"]);
								DataTable dataTable = this.lb.GetLabelByLabelID(labelID);
								if (dataTable.Rows.Count == 1)
								{
									a = dataTable.Rows[0]["StaticOutPut"].ToString();
								}
								else
								{
									base.Response.Write("你要找的标签不存在");
									base.Response.End();
								}
							}
							catch
							{
								base.Response.Write("你要找的标签不存在");
								base.Response.End();
							}
						}
					}
				}
				else
				{
					if (base.Request["name"] != null && base.Request["name"] != "")
					{
						DataTable dataTable = (DataTable)this.Session[base.Request["name"]];
						if (dataTable.Rows.Count > 0)
						{
							DataRow dataRow = dataTable.Rows[0];
							string text2 = dataRow["OutPutType"].ToString();
							a = dataRow["StaticOutPut"].ToString();
						}
						dataTable.Dispose();
					}
				}
			}
			if (!(a != "") || this.LabelName.Text == null || !(this.LabelName.Text != ""))
			{
				this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "msg", "<script>alert('此标签非静态标签，请重新设置再生成！');location.href='Admin_Lable.aspx'</script>");
			}
		}
	}
}
